﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Project01
{
    class MonsterType06 : Monster
    {
        float Angle;
        TimeSpan TimeCreateBullets;
        public MonsterType06(Game game)
            : base(game)
        {
            this.ObjectTexture = game.Content.Load<Texture2D>("Images/Monster/Mtype06");
            this.Sprite = new AnimationSprite(ObjectTexture, 1, 6);
            this.game = game;
            this.Type = 6;
            this.Health = 1;
            this.Speed = 0.5f;
           // Sprite.Position = new Vector2(300, 300);
        }
        public override void Update(GameTime gameTime)
        {
            Angle += (float)gameTime.ElapsedGameTime.TotalSeconds;
            TimeCreateBullets += gameTime.ElapsedGameTime;
            if(this.Sprite.Position.Y>=0+this.Sprite.RecHeight)
            if (TimeCreateBullets >= TimeSpan.FromSeconds(0.5f))
            {
                CreateBullets(this.Sprite.Position);
                TimeCreateBullets = TimeSpan.Zero;
            }
            UpdateBullets(5);
            this.Sprite.Position = Move.MoveVertical(this.Sprite.Position, -this.Speed);
            Active = CheckPosition(this.Sprite.Position);
            base.Update(gameTime);
        }
        private void CreateBullets(Vector2 Position)
        {
            Bullets B = new Bullets(game, "Images/Bullets/Monster/B_M_Type02", 1, 1);
            B.Sprite.Position = Position;
            B.Sprite.Rotation = Angle;
            Mbullets.Add(B);
        }
        private void UpdateBullets(float Distance)
        {
            if (this.Type == 6)
            {
                for (int i = 0; i < Mbullets.Count; i++)
                {
                   // Mbullets[i].Sprite.Rotation = Angle;
                    Mbullets[i].Sprite.Update();
                    Mbullets[i].Sprite.Position += new Vector2(Move.toAngle(Mbullets[i].Sprite.Rotation).X * Distance, Move.toAngle(Mbullets[i].Sprite.Rotation).Y * Distance);
                }
            }
        }
        public override void Draw(SpriteBatch SpriteBatch)
        {
            for (int i = 0; i < Mbullets.Count; i++)
            {
                Mbullets[i].Draw(SpriteBatch);
            }
            base.Draw(SpriteBatch);
        }
       
    }
}
